<template>
  <view class="profile-container" @click="clickhandle($event)">
    <!-- 用户信息区域 -->
    <view class="user-header">
      <view class="user-avatar">
        <image src="/static/images/人物.png" alt="张伟的头像" class="avatar"/>
      </view>
      <view class="user-info">
        <text class="username">{{user.username}}</text>
        <text class="user-bio">{{user.type || "粉丝"}} | {{pagedata.fars.num||0}}</text>
		<view class="logout" :class="opmenuflag?'active':''" @click="togglemenu" data-t="outmenu" >
		<text class="outtext">⋮</text>
		<view class="outbtn" @click="outlog">退出登录</view>
		</view>
      </view>
    </view>

    <!-- 数据统计区域 -->
    <view class="stats-section">
      <view class="stat-item" @click="toMypages">
        <text class="stat-value">{{pagedata.pages?pagedata.pages.items.length:0}}</text>
        <text class="stat-label">文章</text>
      </view>
     <view class="stat-item">
        <text class="stat-value">{{pagedata.fars.num||0}}</text>
        <text class="stat-label">粉丝</text>
      </view>
      <view class="stat-item">
        <text class="stat-value">{{pagedata.good.num || 0}}</text>
        <text class="stat-label">点赞</text>
      </view>
    </view>

    <!-- 资料编辑按钮 -->
    <button class="edit-btn" @click="toLog">切换登录</button>

    <!-- 内容管理区域 -->
    <view class="menu-section">
      <text class="section-title"></text>
      <view class="menu-list">
		  
        <view class="menu-item" @click="toMypages">
          <view class="menu-icon">📄</view>
          <text class="menu-text">我的文章</text>
          <view class="menu-arrow">›</view>
        </view>
       <!-- <view class="menu-item">
          <view class="menu-icon">❤️</view>
          <text class="menu-text">我的收藏</text>
          <view class="menu-arrow">›</view>
        </view>
        <view class="menu-item">
          <view class="menu-icon">💬</view>
          <text class="menu-text">我的评论</text>
          <view class="menu-arrow">›</view>
        </view> -->
		<view class="menu-item" >
          <view class="menu-icon">88</view>
          <text class="menu-text" @click="topublic">投稿</text>
          <view class="menu-arrow">›</view>
        </view> 
		<view class="menu-item">
          <view class="menu-icon">77</view>
          <text class="menu-text" @click="toFeedback">反馈意见</text>
          <view class="menu-arrow">›</view>
        </view>
      </view>
    </view>
 

  </view> 
</template>


<script>
	import myrequest from "@/untils/request.js"
	export default {
		data() {
			return {
				pagedata:{
					pages:null,   //文章
					fars:{},  //粉丝
					good:{}   //点赞
				},
				opmenuflag:false
			}
		},
		computed:{
			user(){
				return this.$store.state.user
			}
		},
		methods: {
			toLog(){
				uni.navigateTo({
					url:"/pages/router/login/login"
				})
			},
			// 获取用户文章 - 文章展示 -文章详情
			getUserpage(){
				myrequest.getuserpage(this.$store.state.token,1,20)
				.then(r=>{    
					this.pagedata.pages = r.data.data
				})
			},
			topublic(){
				
				uni.switchTab({
					url:"/pages/edit/edit"
				})
			},
			toMypages(){
				uni.navigateTo({
					url:"/pages/router/my/mypages"
				})
			},
			toFeedback(){
				uni.navigateTo({
					url:"/pages/router/my/feedback"
				})
			},
			clickhandle(e){
				if(!this.opmenuflag) return
				if(e.target.dataset.t !== "outmenu"){  //不是菜单键 关闭
					this.opmenuflag = false
				}
			},
			togglemenu(){
				this.opmenuflag = !this.opmenuflag
			},
			outlog(){
				uni.removeStorage({
					key:"token",
				}).then(()=>{
					this.$store.commit("SET_USER",null)  //全局保存用户
					this.$store.commit("SET_TOKEN","")
					this.$store.commit("SET_ISLOGIN",false)  
					this.getUserpage()    //异步
				})
				
				
			}
		},
		onLoad(){
			myrequest.autologin().then((r)=>{   //自动登录
				this.$store.commit("SET_USER",r.user.data.data)  //全局保存用户
				this.$store.commit("SET_TOKEN",r.token)  
				this.getUserpage()    //异步
			})
			uni.$on("login",this.getUserpage)
		},
		onUnload() {
			uni.$off("login")
		}
	}
</script>

<style>
.profile-container {
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  min-height: 100vh;
  padding-bottom: 70px;
  box-sizing: border-box;
}

/* 用户头部样式 */
.user-header {
  padding: 30px 20px 20px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
}
.user-avatar {
  margin-right: 15px;
}
.avatar {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 2px solid #e8e8e8;
}
.user-info {
	position: relative;
  flex: 1;
}
.username {
  margin: 0 0 5px;
  font-size: 22px;
  font-weight: 600;
}
.user-bio {
  margin: 0 0 0 10px;
  font-size: 14px;
  color: #666;
}

/* 数据统计区 */
.stats-section {
  display: flex;
  justify-content: space-around;
  padding: 20px 0;
  border-bottom: 1px solid #f0f0f0;
}
.stat-item {
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 20px;
  font-weight: bold;
  color: #333;
}
.stat-label {
  display: block;
  font-size: 13px;
  color: #888;
  margin-top: 5px;
}

/* 登录按钮 */
.edit-btn {
  width: 90%;
  margin: 20px auto;
  padding: 12px;
  display: block;
  background: #4a7aff;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: transform .3s;
}
.edit-btn:active{
	/* animation: qt 1s 0s; */
	transform: scale(0.9);
}

/* 菜单区域 */
.menu-section {
  padding: 0 20px;
  margin-top: 15px;
}
.section-title {
  margin: 10px 0 15px;
  font-size: 16px;
  font-weight: 500;
  color: #555;
}
.menu-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.menu-item {
  display: flex;
  align-items: center;
  padding: 15px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  transition: all .3s;
}
.menu-item:last-child {
  border-bottom: none;
}
.menu-icon {
  margin-right: 12px;
  font-size: 18px;
  color: #4a7aff;
}
.menu-text {
  flex: 1;
  font-size: 16px;
}
.menu-arrow {
  font-size: 20px;
  color: #ccc;
}

/* 底部导航 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  padding: 12px 0;
  background: #fff;
  border-top: 1px solid #eee;
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.nav-icon {
  font-size: 20px;
  margin-bottom: 4px;
}
.nav-text {
  font-size: 12px;
  color: #888;
}
.nav-item.active .nav-icon,
.nav-item.active .nav-text {
  color: #4a7aff;
}

.menu-item:active{
	filter: brightness(0.7);
	/* background-color: #ccc; */
}

@keyframes qt{
	25%{transform: scale(0.8);},
	60%{transform: scale(1.15);},
	80%{transform: scale(0.9);},
	90%{transform: scale(1.1);},
	100%{transform: scale(1);}
}

.logout{
	/* border: black 1px solid; */
	position: absolute;
	text-align: center;
	width: 20%;
	right: 8%;
	top: 50%;
	transform: translateY(-50%);
}

.logout text{
	font-size: 25px;
	font-weight: 600;
	pointer-events: none;
}

.logout.active .outbtn{
		height: 30px;
}

.outbtn{
	display: flex;
	justify-content: center;
	align-items: center;
	position: absolute;
	right: 50%;
	transform: translateX(50%);
	z-index: 2;
	background-color: #ff5500;
	border-radius: 5px;
	color: white;
	width: 80px;
	height: 30px;
	font-size: 1em;
	transition: all .5s;
	height: 0;
	overflow: hidden;
}
</style>
